package com.objectproject.main.dao;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.objectproject.main.dao.iface.MyPrimitiveDAO;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveCollectionMapper;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveDateMapper;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveIntegerMapper;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveRealMapper;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveTextMapper;
import com.objectproject.main.dao.mybatis.mapper.primitive.MyPrimitiveTimeMapper;
import com.objectproject.main.model.primitive.MyPrimitiveCollection;
import com.objectproject.main.model.primitive.MyPrimitiveDate;
import com.objectproject.main.model.primitive.MyPrimitiveImage;
import com.objectproject.main.model.primitive.MyPrimitiveInteger;
import com.objectproject.main.model.primitive.MyPrimitiveReal;
import com.objectproject.main.model.primitive.MyPrimitiveText;
import com.objectproject.main.model.primitive.MyPrimitiveTime;

@Repository
public class MyPrimitiveDAOImpl implements MyPrimitiveDAO {

	private static final Logger logger = LoggerFactory.getLogger(MyPrimitiveDAOImpl.class);
	
	@Autowired
	SqlSession sqlSession;
	
	@Override
	public MyPrimitiveText selectMyPrimitiveText(long primitiveId) {
		logger.info("Method invocation : getMyPrimitiveText(" + primitiveId + ")");
		
		return sqlSession.getMapper(MyPrimitiveTextMapper.class).getMyPrimitiveTextById(primitiveId);
	}

	@Override
	public MyPrimitiveCollection selectMyPrimitiveCollection(long primitiveId) {
		logger.info("Method invocation : getMyPrimitiveCollection(" + primitiveId + ")");
		return sqlSession.getMapper(MyPrimitiveCollectionMapper.class).getMyPrimitiveCollectionById(primitiveId);
	}

	@Override
	public long insertMyPrimitiveText(MyPrimitiveText myPrimitiveText) {
		
		logger.info("Method invocation : insertMyPrimitiveText");
		
		sqlSession.getMapper(MyPrimitiveTextMapper.class).insertMyPrimitiveText(myPrimitiveText);
		return myPrimitiveText.getPrimitiveId(); 
	}

	@Override
	public long insertMyPrimitiveCollection(
			MyPrimitiveCollection myPrimitiveCollection) {
		sqlSession.getMapper(MyPrimitiveCollectionMapper.class).insertMyPrimitiveCollection(myPrimitiveCollection);
		
		return 0;
	}

	@Override
	public void deleteMyPrimitiveText(MyPrimitiveText myPrimitiveText) {
		sqlSession.getMapper(MyPrimitiveTextMapper.class).deleteMyPrimitiveText(myPrimitiveText);
	}

	@Override
	public void deleteMyPrimitiveCollection(MyPrimitiveCollection myPrimitiveCollection) {
		sqlSession.getMapper(MyPrimitiveCollectionMapper.class).deleteMyPrimitiveCollection(myPrimitiveCollection);

	}
	
	@Override
	public MyPrimitiveImage selectMyPrimitiveImage(long primitiveId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public MyPrimitiveInteger selectMyPrimitiveInteger(long primitiveId) {
		return sqlSession.getMapper(MyPrimitiveIntegerMapper.class).getMyPrimitiveIntegerById(primitiveId);
	}

	@Override
	public long insertMyPrimitiveImage(MyPrimitiveImage myPrimitiveImage) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long insertMyPrimitiveInteger(MyPrimitiveInteger myPrimitiveInteger) {
		
		logger.info("Method invocation : insertMyPrimitiveInteger");
		
		sqlSession.getMapper(MyPrimitiveIntegerMapper.class).insertMyPrimitiveInteger(myPrimitiveInteger);
		return myPrimitiveInteger.getPrimitiveId(); 
	}
	
	@Override
	public void deleteMyPrimitiveImage(MyPrimitiveImage myPrimitiveImage) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteMyPrimitiveInteger(MyPrimitiveInteger myPrimitiveInteger) {
		sqlSession.getMapper(MyPrimitiveIntegerMapper.class).deleteMyPrimitiveInteger(myPrimitiveInteger);
	}

	@Override
	public MyPrimitiveDate selectMyPrimitiveDate(long primitiveId) {
		return sqlSession.getMapper(MyPrimitiveDateMapper.class).getMyPrimitiveDateById(primitiveId);
	}

	@Override
	public long insertMyPrimitiveDate(MyPrimitiveDate myPrimitiveDate) {
		logger.info("Method invocation : insertMyPrimitiveDate");
		
		sqlSession.getMapper(MyPrimitiveDateMapper.class).insertMyPrimitiveDate(myPrimitiveDate);
		return myPrimitiveDate.getPrimitiveId(); 
	}

	@Override
	public void deleteMyPrimitiveDate(MyPrimitiveDate myPrimitiveDate) {
		sqlSession.getMapper(MyPrimitiveDateMapper.class).deleteMyPrimitiveDate(myPrimitiveDate);
	}

	@Override
	public MyPrimitiveTime selectMyPrimitiveTime(long primitiveId) {	
		return sqlSession.getMapper(MyPrimitiveTimeMapper.class).getMyPrimitiveTimeById(primitiveId);
	}

	@Override
	public long insertMyPrimitiveTime(MyPrimitiveTime myPrimitiveTime) {
		return sqlSession.getMapper(MyPrimitiveTimeMapper.class).insertMyPrimitiveTime(myPrimitiveTime);
	}

	@Override
	public void deleteMyPrimitiveTime(MyPrimitiveTime myPrimitiveTime) {
		sqlSession.getMapper(MyPrimitiveTimeMapper.class).deleteMyPrimitiveTime(myPrimitiveTime);
	}

	@Override
	public MyPrimitiveReal selectMyPrimitiveReal(long primitiveId) {
		return sqlSession.getMapper(MyPrimitiveRealMapper.class).getMyPrimitiveRealById(primitiveId);
	}

	@Override
	public long insertMyPrimitiveReal(MyPrimitiveReal myPrimitiveReal) {
		return sqlSession.getMapper(MyPrimitiveRealMapper.class).insertMyPrimitiveReal(myPrimitiveReal);
	}

	@Override
	public void deleteMyPrimitiveReal(MyPrimitiveReal myPrimitiveReal) {
		sqlSession.getMapper(MyPrimitiveRealMapper.class).deleteMyPrimitiveReal(myPrimitiveReal);
	}

}
